<?php
require_once 'classes/View.php';
require_once 'classes/DB.php';

session_start();

global $pageOn;
$pageOn = basename($_SERVER['PHP_SELF']);
/*View*/ $view = new View();

if (isset($_SESSION['user']))
{
	header('Location: index.php');
}
else if (!count($_REQUEST))
{
	$view->display('login');
}
else
{
	/*User*/ $user = new User(DB::getInstance());
	$user->setUserName($_REQUEST['user_name']);
	$user->setPassword($_REQUEST['password']);
	if ($user->login())
	{
		$_SESSION['user'] = $user;
		header('Location: index.php');
	}
	else
	{
		$view->data['error'] = 'Login failure';
		$view->display('login');
	}
}
?>